package com.yphone.ui.ysj.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.yphone.tools.MyLog;
import com.yphone.ui.ysj.bean.RemoteConnectBean;
import com.yphone.ui.ysj.view.*;


import java.util.List;

public class ViewPageCardAdapter extends PagerAdapter {
    private Context context;
    private List<Object> list;

    public ViewPageCardAdapter(Context context2, List<Object> list2) {
        this.context = context2;
        this.list = list2;
    }

    public void appList(List<Object> list2) {
        this.list = list2;
        notifyDataSetChanged();
    }


    public int getCount() {
        if (this.list == null) {
            return 1;
        }
        return this.list.size();
    }
//    /**
//     * 页面宽度所占ViewPager测量宽度的权重比例，默认为1
//     */
//    @Override
//    public float getPageWidth(int position) {
//        return (float) 0.8;
//    }


//    public int getItemPosition(@NonNull Object object) {
//        return -2;
//    }

    @NonNull
    public Object instantiateItem(ViewGroup container, int position) {
        if (position == 0) {

            YSJAddDeviceView view1 = new YSJAddDeviceView(this.context);
            container.addView(view1);
            return view1;
        }
        else if (this.list.get(position) instanceof RemoteConnectBean) {
            YSJNewWelFarePageView view = new YSJNewWelFarePageView(this.context, (RemoteConnectBean) this.list.get(position));
            container.addView(view);
            return view;
        }
//        else {
//            YSJCloudHomePageView view2 = new YSJCloudHomePageView(this.context);
//            container.addView(view2);
//            view2.setData((OrderInfoRespone) this.list.get(position), position, this.list.size());
//            return view2;
//        }
        return null;
    }

    public void destroyItem(ViewGroup container, int position, Object object) {
//        if (object instanceof YSJCloudHomePageView) {
//            ((YSJCloudHomePageView) object).stopConnect();
//        }
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    public void remove(int position) {
        if (this.list != null && this.list.size() > position) {
            this.list.remove(position);
            notifyDataSetChanged();
        }
    }

    public void notifyView(List<Object> list2){
        this.list = list2;
        notifyDataSetChanged();
    }
}